<template>
  <div class="container">
    <div class="box login" ref="login">
      <div class="form-content">
        <h1>欢迎回来</h1>
        <form action="#" class="form">
          <div>
            <i class="iconfont icon-zhanghao"></i>
            <input type="text" v-model:value="loginUser.sid" placeholder="账号">
          </div>
          <div>
            <i class="iconfont icon-mima"></i>
            <input type="password" v-model:value="loginUser.password" placeholder="密码">
          </div>
          <div class="btn">
            <button @click="login">登录</button>
          </div>
        </form>
        <p class="btn-something">
          注册一个账号？<span class="signupbtn" @click="signupbtn">注册</span>
        </p>
      </div>
    </div>
    <div class="box signup" ref="signup">
      <div class="form-content">
        <h1>注册～</h1>
        <form action="#" class="form">
          <div>
            <i class="iconfont icon-zhanghao"></i>
            <input type="text" v-model:value="loginUser.sid" placeholder="账号">
          </div>
          <div>
            <i class="iconfont icon-mima"></i>
            <input type="password" v-model:value="loginUser.password" placeholder="输入密码">
          </div>
          <div>
            <i class="iconfont icon-mima"></i>
            <input type="password" v-model:value="confirm" placeholder="确认密码">
          </div>
          <div class="btn">
            <button @click="signup">注册</button>
          </div>
        </form>
        <p class="btn-something">
          已经有账号？<span class="loginbtn" @click="loginbtn">登录</span>
        </p>
      </div>
    </div>
  </div>
</template>

<script>
import {login} from "@/api/au";
import {mapMutations} from "vuex";
import {saveToken} from "@/utils/token";

export default {
  name: "LoginView",
  data() {
    return {
      loginUser: {
        sid: '',
        password: '',
      },
      confirm: ''
    }
  },
  computed: {},
  methods: {
    ...mapMutations(['saveUser']),
    login() {
      login(this.loginUser).then(res => {

        if (res.code === 10000) {
          this.saveUser(res.data.user)
          saveToken("epidemic_token", res.data.jwt)
          this.$router.push("/")
        } else {
          alert("账号密码错误")
          this.user.sid = '';
          this.user.password = '';
        }

      })
    },
    signup() {
      console.log("signup")
      console.log(this.user)
      console.log(this.confirm)
    },
    loginbtn() {
      this.$refs.login.style.transform = "rotateY(0deg)";
      this.$refs.signup.style.transform = "rotateY(-180deg)";
      this.confirm = null;
    },
    signupbtn() {
      this.$refs.login.style.transform = "rotateY(180deg)";
      this.$refs.signup.style.transform = "rotateY(0deg)";
      this.confirm = null;
    }
  }
}
</script>

<style lang="css">

.container {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 20rem;
  height: 20rem;
  perspective: 1500px;
  -webkit-perspective: 1500px;
  -moz-perspective: 1500px;
}

.box {
  position: absolute;
  top: 0;
  left: 0;
  width: 20rem;
  height: 20rem;
  border-radius: 10px;
  cursor: pointer;
  backface-visibility: hidden;
  transition: all 0.5s;
  user-select: none;
}

.signup {
  /* background-color: blue; */
  transform: rotateY(-108deg);
}

.container .form-content {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  box-shadow: 0 0 1px #3399ff;
  border-radius: 30px;
  background-color: #fff;
}

.container .form-content .avtar .pic img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.container .form-content h1 {
  font-size: 1.6rem;
}

.container .form {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}

.container .form input {
  width: 16rem;
  padding: 0.8rem;
  padding-left: 3rem;
  outline: none;
  border: none;
  border-radius: 15px;
  box-shadow: 0 0 3px rgba(0, 0, 0, 0.2);
  margin: 5px;
}

.container .form div {
  position: relative;
}

.container .form div .iconfont {
  position: absolute;
  top: 18px;
  left: 25px;
}

.container .form .btn {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  margin-top: 25px;
}

.container .form .btn button {
  text-transform: uppercase;
  padding: 8px;
  border: none;
  outline: none;
  background-color: #0066ff;
  color: #fff;
  width: 12rem;
  border-radius: 30px;
  cursor: pointer;
}

.container .btn-something {
  color: #888;
  font-size: 14px;
}

.container .btn-something span {
  color: #0066ff;
  cursor: pointer;
  font-weight: 500;
}

svg {
  position: absolute;
  bottom: 0;
  z-index: -1;
}


</style>